#include <iostream>
#include<unordered_map>

using namespace std;

int n, ret;

int main()
{
	cin >> n;
	unordered_map<string, int> mp;
	while(n--)
	{
		string a, b;
		cin >> a >> b;
		a = a.substr(0, 2);
		
		if(a == b)
		    continue;
		ret += mp[b + a];
		mp[a + b]++;
	}
	cout << ret << endl;
	return 0;
}
